package com.jrzh.mvc.model.sys;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import com.google.gson.annotations.Expose;
import com.jrzh.framework.annotation.UniqueValue;
import com.jrzh.framework.base.model.GeneralModel;
@Entity
@Table(name="sys_roles")
public class RoleModel extends GeneralModel{

	@Column(name="_code")
	@NotNull(message="role.code.validate.not_null")
	@UniqueValue(message = "role.code.validate.unique")
	private String code;
	
	@Column(name="_name")
	@NotNull(message="role.name.validate.not_null")
	private String name;
	
	@Column(name="_remark")
	@Size(min = 0, max = 500)
	private String remark;
	
	@ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "sys_roles_resources", joinColumns = { @JoinColumn(name = "_role_id") }, inverseJoinColumns = { @JoinColumn(name = "_res_id") })
	private  List<ResourcesModel> resources = new ArrayList<ResourcesModel>();
	
	@ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "sys_users_roles", joinColumns = { @JoinColumn(name = "_role_id") }, inverseJoinColumns = { @JoinColumn(name = "_user_id") })
	@Expose
	private List<UserModel> users = new ArrayList<UserModel>();
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public List<ResourcesModel> getResources() {
		return resources;
	}

	public void setResources(List<ResourcesModel> resources) {
		this.resources = resources;
	}

	public List<UserModel> getUsers() {
		return users;
	}

	public void setUsers(List<UserModel> users) {
		this.users = users;
	}
}
